﻿using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows;
using System.Windows.Media;

namespace Zero.UControl.Base.Helper.Base
{
    internal class DrawShapeCommand : IDrawingCommand
    {
        public Shape? Shape { get; private set; }
        private readonly Canvas _canvas;
        private readonly ShapeKind _kind;
        private readonly Rect _rect;
        private readonly Brush _stroke;
        private readonly double _thick;

        public DrawShapeCommand(Canvas c, ShapeKind k, Rect r, Brush s, double t)
        {
            _canvas = c;
            _kind = k;
            _rect = r;
            _stroke = s;
            _thick = t;
        }

        public void Execute()
        {
            Shape = _kind switch
            {
                ShapeKind.Rectangle => new Rectangle { Width = _rect.Width, Height = _rect.Height },
                ShapeKind.Ellipse => new Ellipse { Width = _rect.Width, Height = _rect.Height },
                _ => throw new NotSupportedException()
            };
            Shape.Stroke = _stroke; Shape.StrokeThickness = _thick;
            Canvas.SetLeft(Shape, _rect.X);
            Canvas.SetTop(Shape, _rect.Y);
            _canvas.Children.Add(Shape);
        }
        public void UnExecute()
        {
            if (Shape != null)
                _canvas.Children.Remove(Shape);
        }
    }
}
